import 'package:extended_tabs/extended_tabs.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sports_new/controller/record/data_logic.dart';
import 'package:sports_new/utils/mode_config.dart';
import 'package:sports_new/widgets/loading/loading_widget.dart';

import '../../resources/colours.dart';
import '../../resources/styles.dart';
import '../../utils/utils.dart';
import '../../widgets/base/qkd_indicator.dart';

class DataPage extends StatefulWidget {
  const DataPage({super.key});

  @override
  State<DataPage> createState() => _DataPageState();
}

class _DataPageState extends State<DataPage> {
  @override
  Widget build(BuildContext context) {
    final DataLogic logic = Get.put(DataLogic());

    return GetBuilder<DataLogic>(
      builder: (logic) {
        return LoadingWidget<bool>(
          isLoading: false,
          data: false,
          reconnect: logic.getRefresh,
          child: () => Scaffold(
            body: Container(
              decoration: const BoxDecoration(
                gradient: LinearGradient(
                    colors: [Colours.white,Colours.greyF2F3F7],
                    begin: Alignment.topCenter,end: Alignment.bottomCenter,
                    stops: [0.2,0.4]
                ),
              ),
              child: Stack(
                alignment: Alignment.topCenter,
                children: [
                  Image.asset(
                      Utils.getImgPath("nav_head_back.png"),
                      width: Get.width,height: Get.width*128/375
                  ),
                  Column(
                    children: [
                      AppBar(
                        backgroundColor: Colours.transparent,
                        title: Styles.tabbar(
                          tabs: [
                            if(ModeConfig.ai)
                              Image.asset(
                                logic.index == 0
                                    ? Utils.getImgPath("ai_choose.png")
                                    : Utils.getImgPath("ai_unchoose.png"),
                                width: 68,
                                height: 44,
                              ),
                            Image.asset(
                                logic.index == (ModeConfig.ai?1:0)
                                    ? Utils.getImgPath("record_choose.png")
                                    : Utils.getImgPath("record_unchoose.png"),
                                width: 68,
                                height: 44),
                          ],
                          controller: logic.tabController,
                          scrollable: true,
                          labelPadding: const EdgeInsets.symmetric(horizontal: 6),
                          indicatorBottom: 6,
                          labelColor: Colours.white,
                          unselectedLabelColor: Colours.white,
                          onTap: (index) => Utils.onEvent("data_tab",params: {"tab": index})
                        ),
                      ),
                      Expanded(
                        child: ExtendedTabBarView(
                          controller: logic.tabController,
                          children: logic.page
                        ),
                      ),
                    ],
                  ),
                ],
              ),
            ),
          ),
        );
      }
    );
  }
}
